<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-item label="用户名">
              <j-input placeholder="请输入用户名" v-model="queryParam.username"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-item label="手机号">
              <j-input placeholder="请输入用户名" v-model="queryParam.phone"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-item label="企业名称">
              <j-input placeholder="请输入企业名称" v-model="queryParam.name"></j-input>
            </a-form-item>
          </a-col>

          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-item label="申请状态">
<!--              <j-dict-select-tag placeholder="请选择申请状态" v-model="queryParam.auditState" dictCode="property_state"/>-->
              <a-select default-value="3"  @change="handleChange" ref="xuanze" :value="defaultValue">
                <a-select-option value="">
                  全部
                </a-select-option>
                <a-select-option value="0">
                  未申请
                </a-select-option>
                <a-select-option value="1">
                  未通过
                </a-select-option>
                <a-select-option value="2">
                  已通过
                </a-select-option>
                <a-select-option value="3">
                  待审核
                </a-select-option>


              </a-select>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="4" :lg="7" :md="8" :sm="24">
              <a-form-item label="有效">
                <j-dict-select-tag placeholder="请选择是否有效" v-model="queryParam.isAvailable" dictCode="valid_status"/>
              </a-form-item>
            </a-col>
            <a-col :xl="4" :lg="7" :md="8" :sm="24">
              <a-form-item label="会员">
                <j-dict-select-tag placeholder="请选择是否会员" v-model="queryParam.isMember" dictCode="yn"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
<!--      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->
      <!--<a-button type="primary" icon="download" @click="handleExportXls('客户管理')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="isMember_dictText" slot-scope="text, record">
<!--          <span v-if="record.isMember=='0'">否</span>-->
<!--          <span v-else>是</span>-->
          <a-tag color="red" v-if="record.isMember=='0'">
            否
          </a-tag>
          <a-tag color="blue" v-else>
            是
          </a-tag>

        </template>
        <template slot="isAvailable_dictText" slot-scope="text, record">
          <a-popconfirm  :title="record.isAvailable == 1?'确定禁用吗?':'确定启用吗?'" @confirm="() => handleIsAvailable(record.id)">
            <a-switch checked-children="正常" class="ssss" un-checked-children="锁定" disabled :checked="record.isAvailable == 1?true:false" />
          </a-popconfirm>

        </template>
        <template slot="auditState" slot-scope="text">
          <span>
            <a-tag color="blue" v-if="text=='0'">未申请</a-tag>
            <a-tag color="red" v-else-if="text=='1'">未通过</a-tag>
            <a-tag color="green" v-else-if="text=='2'">已通过</a-tag>
            <a-tag color="pink" v-else>待审核</a-tag>
          </span>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <!--<span>
            <a-popconfirm v-if="record.isAvailable == 1" title="确定禁用吗?" @confirm="() => handleIsAvailable(record.id)">
              <a>禁用</a>
            </a-popconfirm>
            <a-popconfirm v-else title="确定启用吗?" @confirm="() => handleIsAvailable(record.id)">
              <a>启用</a>
            </a-popconfirm>
            <a-divider type="vertical"/>
          </span>-->
          <span v-if="record.auditState == '3'&&record.type==2">
            <a @click="handleExamine(record)">审核</a>
            <a-divider type="vertical"/>
          </span>

          <!--<a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />-->
<!--          <a @click="handleCharge(record)">保证金</a>-->
          <a @click="handleMoney(record)">充值明细</a>

          <a-divider type="vertical" />
          <a @click="handleDetail(record)">详情</a>
          <!--<a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>-->
        </span>

      </a-table>
    </div>

    <customer-modal ref="modalForm" @ok="modalFormOk"></customer-modal>
    <CustomerChargeModal ref="customerChargeModal" @ok="modalFormOk"></CustomerChargeModal>
    <CustomerApproveModal ref="customerApproveModal" @ok="modalFormOk"></CustomerApproveModal>
    <CustomerMoneyModal  ref="customerMoneyModal" @ok="modalFormOk"></CustomerMoneyModal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin1'
  import CustomerModal from './modules/CustomerModal'
  import CustomerApproveModal from './modules/CustomerApproveModal'
  import CustomerChargeModal from './modules/CustomerChargeModal'
  import CustomerMoneyModal from './modules/CustomerMoneyModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import { getAction,putAction,postAction} from '@/api/manage'
  import JInput from '@/components/jeecg/JInput'

  export default {
    name: 'CustomerList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      CustomerModal,
      CustomerApproveModal,
      CustomerChargeModal,
      CustomerMoneyModal,
      JInput
    },
    data () {
      return {
        description: '客户管理管理页面',
        defaultValue:'3',
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'类别',
            align:"center",
            dataIndex: 'type_dictText'
          },

          {
            title:'用户名',
            align:"center",
            dataIndex: 'username'
          },
          {
            title:'企业名称',
            align:"center",
            dataIndex: 'name'
          },
          {
            title:'手机号/法人手机号',
            align:"center",
            dataIndex: 'phone'
          },
          {
            title:'保证金',
            align:"center",
            dataIndex: 'earnestMoney'
          },
          {
            title:'冻结保证金',
            align:"center",
            dataIndex: 'frozenEarnest'
          },
          /*{
            title:'性别',
            align:"center",
            dataIndex: 'gender_dictText'
          },
          {
            title:'邮箱',
            align:"center",
            dataIndex: 'email'
          },
          */
          {
            title:'是否有效',
            align:"center",
            dataIndex: 'isAvailable_dictText',
            scopedSlots: { customRender: 'isAvailable_dictText' }
          },
          {
            title:'是否会员',
            align:"center",
            dataIndex: 'isMember_dictText',
            scopedSlots: { customRender: 'isMember_dictText' }
          },
          {
            title:'会员类型',
            align:"center",
            dataIndex: 'member_type'
          },
          {
            title:'申请状态',
            align:"center",
            dataIndex: 'auditState',
            scopedSlots: { customRender: 'auditState' }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/customer/list",
          delete: "/customer/delete",
          deleteBatch: "/customer/deleteBatch",
          exportXlsUrl: "/customer/exportXls",
          importExcelUrl: "customer/importExcel",
          examine:'/customer/approve/info/', //审核
          isAvailable:"/customer/isAvailable/",//启用禁用
          rechargePage:"/customer/rechargePage/"//查看保证金
        },
        dictOptions:{},
      }
    },
    created() {
      this.queryParam.auditState = 3
      this.loadData()
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },

      //审核
      handleExamine(record){
        console.log(record)
        this.loading = true
        postAction(this.url.examine+record.id).then((res)=>{
          console.log(res)
          record.ruhuishenqingUrl = []
          if(res.success){
            //遍历数组，拆分身份证照片 营业执照照片 申请说明照片
            for (let argument of res.result.material) {
              if (argument.type == 0){//营业执照
                record.yingyezhizhaoUrl = argument.storeUrl
              }else if (argument.type == 1){
                record.shenfenzhengzhengmianUrl = argument.storeUrl
              }else if (argument.type == 2){
                record.shenfenzhengfanmianUrl = argument.storeUrl
              }else if (argument.type == 3){
                // record.ruhuishenqingUrl.push(argument.storeUrl)
                record.ruhuishenqingUrl = argument.fileList
              }else {
                record.otherUrl = argument.storeUrl
              }
            }
            for (let argument1 of res.result.material) {
              let img = new Image()
              img.src = argument1.storeUrl
            }
            // record.storeUrl = "https://yjzx-test.oss-cn-beijing.aliyuncs.com/temp/QQ截图20200619002443_1600049401003.png"
            this.loading = false
            this.$refs.customerApproveModal.edit(record);
            this.$refs.customerApproveModal.title = "审核";
            this.$refs.customerApproveModal.disableSubmit = true;
          }else {
            this.$message.error(res.message)
          }


        })
        // console.log(record)

      },


      //详情
      handleDetail:function(record){
        this.loading = true
        postAction(this.url.examine+record.id).then((res)=>{
          console.log(res)
          record.ruhuishenqingUrl = []
          if(res.success){
            //遍历数组，拆分身份证照片 营业执照照片 申请说明照片
            for (let argument of res.result.material) {
              if (argument.type == 0){//营业执照
                record.yingyezhizhaoUrl = argument.storeUrl
              }else if (argument.type == 1){
                record.shenfenzhengzhengmianUrl = argument.storeUrl
              }else if (argument.type == 2){
                record.shenfenzhengfanmianUrl = argument.storeUrl
              }else if (argument.type == 3){
                // record.ruhuishenqingUrl.push(argument.storeUrl)
                record.ruhuishenqingUrl = argument.fileList
              }else {
                record.otherUrl = argument.storeUrl
              }
            }
            for (let argument1 of res.result.material) {
              let img = new Image()
              img.src = argument1.storeUrl
            }
            this.loading = false
            this.$refs.modalForm.edit(record);
            this.$refs.modalForm.title="详情";
            this.$refs.modalForm.disableSubmit = true;
          }else {
            this.$message.error(res.message)
          }
        })
      },


      //启用禁用
      handleIsAvailable(id){
        console.log(id)
        postAction(this.url.isAvailable+id).then((res)=>{
          console.log(res)
          if (res.success){
            this.$message.success(res.message)

          }else {
            this.$message.error(res.message)
          }
        }).finally(()=>{
          this.loadData()
        })
      },

      handleIsAvailable1(id){
        console.log(id)
      },

      //保证金=========作废 移动到资产管理模块
      handleCharge(record){
        this.loading = true
        getAction(this.url.rechargePage+record.id).then((res)=>{
          console.log(res)
          if (res.success){
            this.loading = false
            let record1 = Object.assign(record,{wholeMoney:res.result.wholeMoney})
            this.$refs.customerChargeModal.edit(record);
            this.$refs.customerChargeModal.title = "添加保证金";
            this.$refs.customerChargeModal.disableSubmit = true;
          }else {
            this.$message.error(res.message)
          }
        })
      },

      //充值明细
      handleMoney(record){
        this.$refs.customerMoneyModal.add(record);
        this.$refs.customerMoneyModal.title = "充值明细";
        this.$refs.customerMoneyModal.disableSubmit = true;
      },

      //查询状态
      handleChange(e){
        console.log(e)
        // this.$refs.xuanze.value = e.toString()
        this.defaultValue = e
        this.queryParam.auditState = e
      },

      //查询重置
      searchReset() {
        this.defaultValue = ''
        this.queryParam = {}
        this.loadData(1);
      },

    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
  .ant-switch-disabled{
    cursor: pointer;
    opacity: 1;
  }
  .ssss{
    cursor: pointer !important;
  }
  .ant-switch{
    background-color: rgb(255, 73, 73);
  }
  .ant-switch-checked{
    background-color: #1890FF !important;
  }
</style>